﻿#include <fstream>
#include <sstream>
#include <string>
#include <unordered_map>
#include <vector>

std::string UTF8ToANSI(const std::string& utf8);

// 读取文件并返回标题行和数据行
std::string readFile(const std::string& filePath, std::vector<std::string>& header, std::vector<std::vector<std::string>>& data) {
  std::string ansiFileName = UTF8ToANSI(filePath);
  std::ifstream file(ansiFileName);
  if (!file.is_open()) {
    return "error：无法打开文件: ";
  }

  std::string line;
  // 读取标题行
  if (std::getline(file, line)) {
    std::istringstream iss(line);
    std::string cell;
    while (std::getline(iss, cell, '\t')) {
      header.push_back(cell);
    }
  }

  // 读取数据行
  while (std::getline(file, line)) {
    std::istringstream iss(line);
    std::vector<std::string> row;
    std::string cell;
    while (std::getline(iss, cell, '\t')) {
      row.push_back(cell);
    }
    if (row.empty())
    {
      continue;
    }
    data.push_back(row);
  }

  file.close();
  return "";
}
